package com.djakapm.swing.component.tab;

import javax.swing.*;

public class Tab extends JTabbedPane{
    private boolean closable;
    private Action afterTabCloseAction;
    private boolean defaultCloseOperation;
    private TabUI tabUI;

    public Tab(){
        this.tabUI = new TabUI(this);
        this.addMouseMotionListener(tabUI.createMouseMotionListener());
        super.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
        super.setUI(tabUI);
        this.setFocusable(false);
        this.setDefaultCloseOperation(true);
    }

    public boolean isClosable(){
        return this.closable;
    }

    public void setClosable(boolean closable){
        this.closable = closable;
    }
    public void setAfterTabCloseAction(Action afterTabCloseAction){
        this.afterTabCloseAction = afterTabCloseAction;
    }

    public Action getAfterTabCloseAction(){
        return this.afterTabCloseAction;
    }

    public boolean isDefaultCloseOperation() {
        return defaultCloseOperation;
    }

    public void setDefaultCloseOperation(boolean defaultCloseOperation) {
        this.defaultCloseOperation = defaultCloseOperation;
    }

    /**
     * Return the index of the tab which the cursor hovered.
     * @return index of hovered tab.
     */
    public int getOverTabIndex(){
        return this.tabUI.getOverTabIndex();
    }

}
